package com.bianguo.android.apushdemo.view.wiget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.Shader;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by Administrator on 2017/8/11.
 */

public class CustomView1 extends View {

    private Context mContext;
    private Paint mPaint;
    private Path mPath;

    public CustomView1(Context context) {
        super(context);
        initView(context);
    }

    public CustomView1(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public CustomView1(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context mContext) {
        this.mContext = mContext;

        mPaint = new Paint();
        mPaint.setStyle(Style.FILL);
        mPaint.setAntiAlias(true);

        mPath = new Path();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        mPaint.setColor(Color.parseColor("#ff0000"));
        mPath.addRect(100, 100, 300, 300, Path.Direction.CW);
        mPath.addCircle(300, 300, 100, Path.Direction.CW);
        mPath.setFillType(Path.FillType.INVERSE_EVEN_ODD);
        canvas.drawPath(mPath,mPaint);

        Shader mShader = new LinearGradient(300, 300, 500, 500, Color.parseColor("#ff0000"), Color.parseColor("#00ff00"), Shader.TileMode.CLAMP);
        mPaint.setShader(mShader);
        canvas.drawCircle(400, 400, 100, mPaint);
    }
}
